package com.caldremch.remoteserviceclient;

import androidx.appcompat.app.AppCompatActivity;

import android.content.ComponentName;
import android.content.Intent;
import android.content.ServiceConnection;
import android.os.Bundle;
import android.os.IBinder;
import android.os.RemoteException;
import android.util.Log;
import android.view.View;

import com.caldremch.remoteserviceserver.IMyAidlInterface;

public class MainActivity extends AppCompatActivity {


    private IMyAidlInterface mAIDLService;


    private ServiceConnection connection = new ServiceConnection() {
        @Override
        public void onServiceConnected(ComponentName name, IBinder service) {


            mAIDLService = IMyAidlInterface.Stub.asInterface(service);

            try {
                mAIDLService.AIDL_Service();
            } catch (RemoteException e) {
                e.printStackTrace();
            }

        }

        @Override
        public void onServiceDisconnected(ComponentName name) {

        }
    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }

    public void bindRemoteService(View view) {
        Log.d("TAG", "View");
        Intent intent = new Intent();
        intent.setAction("com.caldremch.remoteserviceserver.MyService");
        intent.setPackage("com.caldremch.remoteserviceserver");
        bindService(intent,connection, BIND_AUTO_CREATE);

    }
}
